package com.appspot.codelab.docs.server;

import java.io.FileReader;
import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.appspot.codelab.docs.server.auth.AuthenticationManager;

/**
 * The servlet corresponding to the document editor.
 */
public class CodeLabEditorServlet extends HttpServlet {
  
  private static final long serialVersionUID = -4184093752854675998L;

  /**
   * On GET, check and require authentication. If authenticated, write editor page.
   */
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
       throws IOException {
	AuthenticationManager.authenticate(req, resp);
    resp.setContentType("text/html");
    char[] buffer = new char[1028];
    FileReader reader = new FileReader("editor.html");
    int i = 0;
    while ((i = reader.read(buffer, 0, 1028)) > 0) {
      resp.getWriter().write(buffer, 0, i);
    }
  }
  
}

